package com.icard.wx.icardwx.controller;

import com.dsbj.common.model.Dept;
import com.dsbj.common.model.Employee;
import com.dsbj.common.msg.ResponseMessage;
import com.icard.wx.icardwx.model.AllowUser;
import com.icard.wx.icardwx.model.WxUser;
import com.icard.wx.icardwx.service.IEmployeeService;
import com.icard.wx.icardwx.utils.Constants;
import org.springframework.stereotype.Controller;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * @author cjw 2019-09-24
 */
@Controller
@RequestMapping(value = "/employee")
public class EmployeeController extends BaseController {

	@Resource
	private IEmployeeService employeeService;
	


	/**
	 * 根据employeename模糊查询employee信息。
	 *
	 * tip1：传入参数: companyno,employeename。
	 * tip2：employeename中亦可传入employeeno信息。
	 * @param
	 * @return
	 * @author cjw 2019-09-23
	 */
	@RequestMapping("/getEmployeeByNameDim")
	@ResponseBody
	public List<Employee> getEmployeeByNameDim(HttpServletRequest request, String keywords){

		WxUser user = (WxUser) request.getSession().getAttribute(Constants.SESSION_USER);
        if(user==null){
            return new ArrayList<>();
        }

		List<Employee> dataList = new ArrayList<>();
		ResponseMessage<List<Employee>> rsp =  employeeService.searchEmployeeByKeyword(keywords,user.getCompanyno());

		if(rsp!=null&&!CollectionUtils.isEmpty(rsp.getData())){
			dataList = rsp.getData();
		}
		return dataList;
	}
	

}
